<template>
  <div>
    <el-button type="primary" @click="Shen">审核订单</el-button>
    <el-button type="danger" @click="FShen">反审核</el-button>
    <el-button type="success" @click="XiaFa">下发生产</el-button>
    <el-button type="info" @click="printArea ">打印</el-button>
    <el-button type="warning" plain  @click="openDialog">修改价格</el-button>
    <el-dialog v-model="dialogFormVisible " title="修改价格" width="800">
      <el-form :model="from" label-width="120px">
        <el-form-item label="价格">
          <el-input v-model="from.all_price" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="updateMoney">提交</el-button>
        </el-form-item>
      </el-form>
  </el-dialog>
    <!-- <t-layout-page>
    <t-layout-page-item>
      <t-select-table
        :table="table"
        :columns="table.columns"
        use-virtual
        :keywords="{label:'name',value:'id'}"
        @radioChange="radioChange"
      ></t-select-table>
    </t-layout-page-item>
  </t-layout-page> -->
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import { useStore } from 'vuex'
import { ElMessage, ElMessageBox } from 'element-plus'
const store = useStore()
import axios from 'axios'
const dialogFormVisible = ref(false)
const from = reactive({
  o_number: '',
  all_price: ''
})
const printArea  = () => {
      window.print();
    };
const openDialog= () => {
  dialogFormVisible.value = true  
  from.all_price = store.state.selectedRow.all_price
}
const updateMoney=()=>{
  console.log(from.all_price)
  //确定要修改吗
  ElMessageBox.confirm('确定要修改吗？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    console.log(from.all_price)
    axios.post("http://localhost:9991/api/mes_ordermanagement/UpdMoney",{
      all_price:from.all_price,
    }).then(res=>{
      if(res.data>0){
        ElMessage({
          message: '修改成功',
          type: 'success',
        })
        dialogFormVisible.value = false
      }else{
        ElMessage({
          message: '修改失败',
          type: 'error',
        })
      }
    })
  })
}
function Shen() {
  from.o_number = store.state.selectedONumber
  console.log(from.o_number)
  ElMessageBox.confirm('确定审核此订单？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    axios
      .get('http://localhost:9991/api/mes_ordermanagement', {
        params: {
          o_number: from.o_number
        }
      })
      .then((res) => {
        console.log(res.data)
        if (res.data == 1) {
          ElMessage.success({
            message: '审核成功',
            type: 'success'
          })
          // location.reload()
        } else if (res.data == 0) {
          ElMessage.error({
            message: '审核失败、参数为空',
            type: 'error'
          })
          return
        } else if (res.data == -1) {
          ElMessage.error({
            message: '审核失败、已下发此状态不允许审核',
            type: 'error'
          })
          store.state.selectedONumber = ''
          from.o_number = ''
        } else if (res.data == 2) {
          ElMessage.error({
            message: '已审核',
            type: 'error'
          })
          store.state.selectedONumber = ''
          from.o_number = ''
        }
      })
  })
}
const FShen = () => {
  from.o_number = store.state.selectedONumber
  console.log(from.o_number)
  ElMessageBox.confirm('确定审核此订单？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    axios
      .get('http://localhost:9991/api/mes_ordermanagement/Fan', {
        params: {
          o_number: from.o_number
        }
      })
      .then((res) => {
        console.log(res.data)
        if (res.data == 1) {
          ElMessage.success({
            message: '反审核成功',
            type: 'success'
          })
          // location.reload()
        } else if (res.data == 0) {
          ElMessage.error({
            message: '反审核失败、参数为空',
            type: 'error'
          })
          return
        } else if (res.data == -1) {
          ElMessage.error({
            message: '反审核失败、已下发此状态不允许审核',
            type: 'error'
          })
          store.state.selectedONumber = ''
          from.o_number = ''
        } else if (res.data == 2) {
          ElMessage.error({
            message: '当前状态已经未审核',
            type: 'error'
          })
          store.state.selectedONumber = ''
          from.o_number = ''
        }
      })
  })
}
const XiaFa = () => {
  ElMessageBox.confirm('是否确认下发', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    axios
      .post('http://localhost:9991/api/mes_ordermanagement/Xiafa', {
        o_number: store.state.selectedRow.o_number,
        status: store.state.selectedRow.status,
        create_time: store.state.selectedRow.create_time,
        is_ruku: store.state.selectedRow.is_ruku,
        contract_no: store.state.selectedRow.contract_no,
        jiaohuo_date: store.state.selectedRow.jiaohuo_date,
        comment: store.state.selectedRow.comment,
        kh_id: store.state.selectedRow.kh_id,
        kh_name: store.state.selectedRow.kh_name
      })
      .then((res) => {
        console.log(res.data)
        if (res.data > 0) {
          ElMessage.success({
            message: '下发成功',
            type: 'success'
          })
          // location.reload()
        } else if (res.data == 0) {
          ElMessage.error({
            message: '订单未审核',
            type: 'error'
          })
        }
      })
  })
}
// const table = ref({
//       data: [
//         { id: 1, code: 1, name: '物料名称1', spec: '物料规格1', unitName: '吨' },
//         { id: 2, code: 2, name: '物料名称2', spec: '物料规格2', unitName: '吨' },
//         { id: 3, code: 3, name: '物料名称3', spec: '物料规格3', unitName: '吨' },
//         { id: 4, code: 4, name: '物料名称4', spec: '物料规格4', unitName: '吨' },
//         { id: 5, code: 5, name: '物料名称5', spec: '物料规格5', unitName: '吨' },
//         { id: 6, code: 6, name: '物料名称6', spec: '物料规格6', unitName: '吨' },
//         { id: 7, code: 7, name: '物料名称7', spec: '物料规格7', unitName: '吨' },
//         { id: 8, code: 8, name: '物料名称8', spec: '物料规格8', unitName: '吨' },
//         { id: 9, code: 9, name: '物料名称9', spec: '物料规格9', unitName: '吨' },
//         { id: 10, code: 10, name: '物料名称10', spec: '物料规格10', unitName: '吨' },
//         { id: 11, code: 11, name: '物料名称11', spec: '物料规格11', unitName: '吨' },
//         { id: 12, code: 12, name: '物料名称12', spec: '物料规格12', unitName: '吨' },
//         { id: 13, code: 13, name: '物料名称13', spec: '物料规格13', unitName: '吨' }
//       ],
//       columns: [
//         { label: '物料编号', width: '100px', prop: 'code' },
//         { label: '物料名称', width: '149px', prop: 'name' },
//         { label: '规格', width: '149px', prop: 'spec' },
//         { label: '单位', width: '110px', prop: 'unitName' },
//         { label: '物料编号1', width: '149px', prop: 'code' },
//         { label: '物料名称1', width: '149px', prop: 'name' },
//         { label: '规格1', width: '149px', prop: 'spec' },
//         { label: '单位1', width: '110px', prop: 'unitName' },
//         { label: '物料编号11', width: '149px', prop: 'code' },
//         { label: '物料名称11', width: '149px', prop: 'name' },
//         { label: '规格11', width: '149px', prop: 'spec' },
//         { label: '单位11', width: '110px', prop: 'unitName' },
//         { label: '物料编号111', width: '149px', prop: 'code' },
//         { label: '物料名称111', width: '149px', prop: 'name' },
//         { label: '规格111', width: '149px', prop: 'spec' },
//         { label: '单位111', width: '110px', prop: 'unitName' }
//       ]
//     });
//      // 单选
// const radioChange=(row)=>{
//   console.log('传给后台的值', row)
// }
</script>

<style scoped>
@media print {
  body * {
    visibility: hidden;
  }
 .print-area * {
    visibility: visible;
  }
 .print-area {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
  }
}
</style>
